#include <xp/bas/stdlib.h>
#include <xp/bas/stdio.h>
#include <xp/bas/locale.h>
#include <string.h>

#ifdef __linux
#include <mcheck.h>
#endif

int xp_main ()
{

	xp_md5_t md5;
	xp_byte_t digest[16];
	xp_size_t i, n;
	const char* p;

#ifdef __linux
	mtrace ();		
#endif

	xp_setlocale ();

	xp_md5_open (&md5);

	xp_md5_update (&md5, "message digest", 14);
	n = xp_md5_digest (&md5, digest, xp_sizeof(digest));

	for (i = 0; i < n; i++) xp_printf (XP_TEXT("%02x"), digest[i]);
	xp_printf (XP_TEXT("\n"));

	p = "abcdefghijklmnopqrstuvwxyz";
	xp_md5_update (&md5, p, strlen(p));
	n = xp_md5_digest (&md5, digest, xp_sizeof(digest));
	for (i = 0; i < n; i++) xp_printf (XP_TEXT("%02x"), digest[i]);
	xp_printf (XP_TEXT("\n"));

	p = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
	xp_md5_update (&md5, p, strlen(p));
	n = xp_md5_digest (&md5, digest, xp_sizeof(digest));
	for (i = 0; i < n; i++) xp_printf (XP_TEXT("%02x"), digest[i]);
	xp_printf (XP_TEXT("\n"));

	p = "rootrootrootroot";
	xp_md5_update (&md5, p, strlen(p));
	n = xp_md5_digest (&md5, digest, xp_sizeof(digest));
	for (i = 0; i < n; i++) xp_printf (XP_TEXT("%02x"), digest[i]);
	xp_printf (XP_TEXT("\n"));

	xp_md5_close (&md5);
	return 0;
}

